<template>
  <div class="visitor" v-for="(user,index) in users" :key="index" @click="chooseCard(index)"
  >
    <div class="top">
      <div class="left">
        <span class="free">{{ user.isInsure == 1 ? "医保" : "自费" }}</span>
        <span class="username">{{ user.name }}</span>
      </div>
      <div class="right">
        <el-button
            circle
            type="primary"
            size="default"
            icon="Edit"
            @click="editUserHandler(user)"
        ></el-button>
        <el-popconfirm title="确定要删除吗?">
          <template #reference>
            <el-button
                v-if="path==='/user/patient'"
                circle
                type="danger"
                size="default"
                icon="Delete"
                @click="removeByUserId(user)"
            ></el-button>
          </template>
        </el-popconfirm>

      </div>
    </div>
    <div class="bottom">
      <p>证件类型:{{ user.param?.certificatesTypeString }}</p>
      <p>证件号码:{{ user.certificatesNo }}</p>
      <p>用户性别:{{ user.sex == 0 ? "女生" : "男士" }}</p>
      <p>出生日期：{{ user.birthdate }}</p>
      <p>手机号码：{{ user.phone }}</p>
      <p>婚姻状况:{{ user.isMarry == 0 ? "未婚" : "已婚" }}</p>
      <p>当前住址{{ user.param?.cityString }}</p>
      <p>详细地址：{{ user.param?.fullAddress }}</p>
      <!-- 红色的已经选择的盒子 -->

    </div>

    <div class="is-choose" v-if="currentIndex===index">
      已选择
    </div>
  </div>


</template>

<script setup lang="ts">
import useHospitalInfoStore from "@/store/hospital_info";
import {storeToRefs} from "pinia";
import {useRoute} from "vue-router";
import router from "@/router";
import {ref} from "vue";

//获取route路径，判断是从哪个页面进来的
const route = useRoute();
const path = route.path

const infoStore = useHospitalInfoStore();
infoStore.getHospitalPersonData()
const {users} = storeToRefs(infoStore)

//编辑用户信息

const $emits = defineEmits(["editUserInfoHandler", "conveyValueIndex"]);
const editUserHandler = (user: any) => {
  router.push({
    path: "/user/patient",
    query: {
      scene: 1,
      userId: user.id
    }
  })

  $emits("editUserInfoHandler", user)
}

const removeByUserId = (user: any) => {
  infoStore.removeByUserIdData(user.id)
  //再次请求数据
  infoStore.getHospitalPersonData()
}
const currentIndex = ref(-1)
const chooseCard = (index: number) => {
  currentIndex.value = index
  $emits("conveyValueIndex", index)
}
</script>

<style scoped lang="less">
.visitor {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  width: 33%;
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);


  .is-choose {
    left: 0;
    right: 0;
    margin: 50% auto;
    position: absolute;
    color: red;
    font-size: 25px;
    transform: rotate(-60deg);
    text-align: center;
    line-height: 200px;
    width: 200px;
    height: 200px;
    border: 1px solid red;
    border-radius: 50%;
    opacity: 0.5;
  }


  .top {
    width: 100%;
    height: 60px;
    background: #e5e5e5;
    display: flex;
    justify-content: space-around;
    align-items: center;

    .left {
      .free {
        background: white;
        padding: 5px;
        font-size: 12px;
        margin-right: 5px;
        border-radius: 10px;
      }

      .username {
        color: #7f7f7f;
      }
    }
  }

  .bottom {
    position: relative;
    padding: 20px;

    p {
      line-height: 40px;
    }

    .confirm {
      position: absolute;
      width: 200px;
      height: 200px;
      color: red;
      border-radius: 50%;
      border: 1px dashed red;
      text-align: center;
      line-height: 200px;
      left: 20%;
      top: 20%;
      opacity: 0.5;
      transform: rotate(35deg);
      font-weight: 900;
    }

    .confirm-enter-from {
      transform: scale(1);
    }

    .confirm-enter-active {
      transition: all 0.3s;
    }

    .confirm-enter-to {
      transform: scale(1.2);
    }
  }
}
</style>
